#ifndef GAMEROOM_H
#define GAMEROOM_H

#include <QWidget>
#include "gamehall.h"
#include <QTimer>
#include <QMessageBox>
#include <QIcon>
#include <QPushButton>
#include <QHBoxLayout>
#include <QDebug>
#include <QFile>
#include <QDateTime>

namespace Ui {
class GameRoom;
}

#define SIMPLE 200
#define NORMAL 125
#define HARD 50

enum SnakeDirect
{
    UP=0,
    DOWN,
    LEFT,
    RIGHT
};

enum SnakeFood
{
    CAFE=0,
    KORA,
    MUSHROOM,
    ORANGE,
    TOAST
};

class GameRoom : public QWidget
{
    Q_OBJECT

public:
    explicit GameRoom(QWidget *parent = nullptr);
    ~GameRoom();

    void paintEvent(QPaintEvent *event);

private slots:
    void on_up_clicked();

    void on_down_clicked();

    void on_left_clicked();

    void on_right_clicked();

    void on_exit_clicked();

    bool checkFail();  //判断游戏是否结束

    void moveUp();
    void moveDown();
    void moveLeft();
    void moveRight();

    void createFood();

    void on_start_clicked();

    void on_stop_clicked();

    void gameOver();

public:
    void SetMode(int speed);


private:
    Ui::GameRoom *ui;

    const int kSnakeNodeWeight=50;  //蛇身宽度
    const int kSnakeNodeHeight=50;  //蛇身高度
    int DefaultSpeed=200;     //贪吃蛇的默认移动速度

    QList<QRectF> snakeList;     //贪吃蛇链表
    QRectF foodRect;   //食物节点

    SnakeDirect moveDirect=SnakeDirect::UP;   //设置蛇默认移动方向为向上
    QTimer *timer;

    bool isGameStart=false;
    bool isover=false;
    QPainter painter;

    int mode=SIMPLE;


};

#endif // GAMEROOM_H
